package com.lagou.cl.service.ipml;

import com.lagou.cl.dao.ResumeDao;
import com.lagou.cl.pojo.Resume;
import com.lagou.cl.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * @author 程  林
 * @date 2020-04-18 18:42
 * @description //
 * @since V1.0.0
 */
@Service
public class ResumeServiceImpl implements ResumeService {


	@Autowired
	private ResumeDao resumeDao;

	@Override
	public List<Resume> queryAll() {

		List<Resume> resumes = resumeDao.findAll();

		return resumes;
	}

	@Override
	public Resume queryById(Long id) {

		Resume resume = new Resume();
		resume.setId(id);
		Example<Resume> example = Example.of(resume);

		Optional<Resume> one = resumeDao.findOne(example);

		return one.get();
	}

	@Override
	public Resume add(Resume resume) {
		return resumeDao.save(resume);
	}


	@Override
	@Transactional(rollbackFor = Exception.class)
	public Resume update(Resume resume) {
		return resumeDao.save(resume);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteById(Long id) {
		resumeDao.deleteById(id);
	}


}
